//
// Copyright (c) 2024 BPer
//

#ifndef SRC_BPERUTIL_BUFFER2_BPERSORTBUFFER_H_
#define SRC_BPERUTIL_BUFFER2_BPERSORTBUFFER_H_

#include <bperutil/BPerType.h>
#include <bperutil/BPerAvType.h>


typedef struct{
	int64_t pts;
	BPerFrame frame;
}BPerSortFrame;

typedef struct{

	uint32_t capacity;
	int32_t cacheNum;
	uint32_t vsize;
	int64_t lastPts;
	BPerSortFrame** frames;
	uint8_t* bufferManager;
}BPerSortBufferSession;

typedef struct{
	BPerSortBufferSession session;
	void (*initFrames)(BPerSortBufferSession* session,int32_t pnum,int32_t unitsize);
	void (*putFrame)(BPerSortBufferSession* session,int64_t pts,BPerFrame* pframe);
	void (*removeFirst)(BPerSortBufferSession* session);
	BPerFrame* (*getCurFrameRef)(BPerSortBufferSession* session);
}BPerSortBuffer;

void bPer_create_sortBuffer(BPerSortBuffer* buf,int cacheNum);
void bPer_destroy_sortBuffer(BPerSortBuffer* buf);


#endif /* SRC_BPERUTIL_BUFFER2_BPERSORTBUFFER_H_ */
